package ${basePackage}.cli.command;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import ${basePackage}.generator.MainGenerator;
import ${basePackage}.model.DataModel;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
 * @author wkh
 * 读取json文件生成代码
 */
@Data
@CommandLine.Command(name = "json-generator", description = "读取json文件生成代码", mixinStandardHelpOptions = true)
public class JsonGeneratorCommand implements Callable {
    @CommandLine.Option(names = {"-f", "--file"}, arity = "0..1", interactive = true, description = "json文件路径", echo = true)
    private String filePath;

    @Override
    public Object call() throws Exception {
        //读取json文件，转换成数据模型
        String jsonStr = FileUtil.readUtf8String(filePath);
        DataModel dataModel = JSONUtil.toBean(jsonStr, DataModel.class);
        //生成代码
        MainGenerator.doGenerator(dataModel);
        return 0;
    }
}
